<?php

class Users extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    
    function get_users($atribute,$value){
        $this->db->where($atribute,$value);
        return $this->db->get('user');
    }
    
    function insert($data){
        $data['user_since'] = date('Y-m-d');
        $this->db->insert('user', $data);
        $user_id = $this->db->insert_id();
        $this->db->flush_cache();
        $this->db->set('category_title','Uncategorized');
        $this->db->set('user_id',$user_id);
        $this->db->insert('category');
        return $user_id;
    }
    
    function delete($user_id){
        $this->db->where('user_id', $user_id);
        $this->db->delete('user');
    }
    
    function check_login($email,$password){
        $this->db->where('user_email', $email);
        $this->db->where('user_pwd', $password);
        $query = $this->db->get('user');
        return ($query->num_rows() > 0) ? $query->first_row()->user_id : 0;
    }
        
    function email_check($email){
        $this->db->where('user_email', $email);
        $query = $this->db->get('user');
        return ($query->num_rows() > 0) ? TRUE : FALSE;
    }
    
    //UPDATE
    
    function update_name($user_id,$name){
        $this->db->where('user_id',$user_id);
        $this->db->set('user_name',$name);
        $this->db->update('user');
    }
    
    function update_password($user_id,$pass){
        $this->db->where('user_id',$user_id);
        $this->db->set('user_pwd',$pass);
        $this->db->update('user');
    }
}

?>
